<?php
namespace App\Enums;

enum BorrowStatus: int
{
    case STATUS_BORROWING = 0;
    case STATUS_RETURNED = 1;
    case STATUS_OVERDUE = 2;

    case STATUS_APPLY = 3;

    public function getLabelText(): string
    {
        return match ($this) {
            self::STATUS_BORROWING => '借阅中',
            self::STATUS_RETURNED => '已归还',
            self::STATUS_OVERDUE => '已逾期',
            self::STATUS_APPLY => '预约中',
        };
    }
    public function getLabelHtml()
    {
        return sprintf('<span class="px-2 py-1 rounded-md bg-%s-500 text-%s-500">%s</span>',$this->getThemeColor(),$this->getThemeColor(),$this->getLabelText());
    }
    public function getColor(): string
    {
        return match ($this) {
            self::STATUS_BORROWING => 'danger',
            self::STATUS_RETURNED => 'success',
            self::STATUS_OVERDUE => 'warning',
            self::STATUS_APPLY => 'info',
        };
    }

    public function hasReturn()
    {
        return $this == self::STATUS_RETURNED;
    }
    public static function getFilterValue(): array
    {

        return [
            self::STATUS_BORROWING->value=> '借阅中',
            self::STATUS_RETURNED->value=> '已归还',
           self::STATUS_OVERDUE->value=> '已逾期',
            self::STATUS_APPLY->value=> '预约中',
        ];
    }

    private function getThemeColor()
    {
        return match ($this) {
            self::STATUS_BORROWING => 'red',
            self::STATUS_RETURNED => 'green',
            self::STATUS_OVERDUE => 'gray',
            self::STATUS_APPLY => 'info',
        };
    }
}
